<?php
namespace IKPHP\Apps\Home\Controllers;

use IKPHP\Common\Models\User as User;
use IKPHP\Common\Models\Setting;
use IKPHP\Common\Controllers\FrontendController;
use IKPHP\Apps\Space\Models\UserNote;
use IKPHP\Apps\Space\Models\UserPhotoAlbum;

use IKPHP\Apps\Group\Models\Group;
use IKPHP\Apps\Group\Models\GroupCate;

class IndexController extends FrontendController
{
    public function initialize()
    {
        parent::initialize();
        $this->user_mod = new User();
		//日记

		$this->note_mod = new UserNote();  
		//个人空间相册推荐
		$this->photo_album_mod = new UserPhotoAlbum();		      
    }
	public function testAction(){
	   $tag_arg = array (
			'uid' => 2,
			'uname' => '下麦',
			'action' => 'login',
			'actionname' => '登录'
		);
        hook('UserScore', 'changeScore', $tag_arg);
	}
    public function indexAction(){
		//活跃会员
		$arrHotUser = $this->user_mod->getHotUser(16);
		$this->assign ( 'arrHotUser', $arrHotUser );
		//统计用户数
		$count_user = $this->user_mod->count(); 
		$this->assign ( 'count_user', $count_user );
		//获取推荐照片
		$arrPhoto = $this->photo_album_mod->getRecommendAlbum(4);
		$this->assign ( 'arrPhoto', $arrPhoto );		
		//获取推荐日记
		
		$arrNote = $this->note_mod->getRecommendNote(14);
		$this->assign ( 'arrNote', $arrNote );	

				
		//推荐小组10个
		$arrRecommendGroups = Group::getRecommendGroup ( 14 );
		foreach ( $arrRecommendGroups as $key => $item ) {
			$arrRecommendGroup [] = $item;
			$arrRecommendGroup [$key] ['groupdesc'] = sub_str($item['groupdesc'],66);
		}
		$this->assign ( 'arrRecommendGroup', $arrRecommendGroup );	
		//获取小组分类
		$groupParentCate = GroupCate::getCates();
		$arrGroupCate = array();
		foreach ($groupParentCate as $key=>$val){
			$arrGroupCate[$key]['parent'] = $val; 
			$arrGroupCate[$key]['child']  = GroupCate::getReferCate($val['cateid']);
		}
		$this->assign ( 'arrGroupCate', $arrGroupCate );	
		
		if(!$this->visitor){ 
			$this->view->cache(array('key' => 'home-index')); 
			if ($this->viewCache->exists('home-index')) {
				return;
			}				
		}
		$this->_config_seo ();
    }
 
	
}